package com.mo.json;

import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson.serializer.DoubleSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.ValueFilter;

/**
 * @author moon.pan
 * @program cyberdata
 * @apiNote
 * @since 2022/3/28
 */
public class StudentValueSerializer implements ValueFilter {
    @Override
    public Object process(Object obj, String name, Object value) {
        SerializeConfig config = SerializeConfig.getGlobalInstance();
        config.put(Double.class, new DoubleSerializer("#.##"));

        if (value instanceof Double){
            return NumberUtil.round((Double) value, 2);
        }
        return value;
    }

//    @Override
//    public Object process(BeanContext context, Object object, String name, Object value) {
//        if (value instanceof Double){
//            return NumberUtil.round((Double) value, 2);
//        }
//        return value;
//    }
}
